package com.wind.trademark.base.dao.impl;


// default package

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import com.wind.trademark.base.dao.CategoryDao;
import com.wind.trademark.base.model.BsCategory;
import com.wind.trademark.base.vo.CategoryVo;
import com.wind.trademark.common.dao.BaseDao;
import com.wind.trademark.common.vo.ComboBean;
import com.wind.trademark.common.vo.PageBean;
import com.wind.trademark.common.vo.PageParam;




@Repository
public class CategoryDaoImpl implements CategoryDao{
	@Autowired
	private BaseDao baseDao;



	@Override
	public PageBean queryCategory(PageParam pageParam,
			Map<String, Object> params) {
		
		String sql= CategorySql.queryCategorySQL(params);
		PageBean pageBean=baseDao.queryPageBeanAndMapping(sql, pageParam,CategoryVo.class, params);

		return pageBean;
	}



	@Override
	public List<ComboBean> goolgeL2Category(String queryParam) {
		String sql= CategorySql.goolgeL2CategorySQL();
		RowMapper<ComboBean> rowMapper = ParameterizedBeanPropertyRowMapper.newInstance(ComboBean.class);
		List<ComboBean> result = baseDao.getNamedParameterJdbcTemplate().query(sql,new MapSqlParameterSource().addValue("queryParam", "%"+queryParam+"%"), rowMapper);
		return result;
	}





	@Override
	public List<ComboBean> goolgeL1AndL2Category(Map<String, Object> params) {
		String sql= CategorySql.goolgeL1AndL2Category(params);
		RowMapper<ComboBean> rowMapper = ParameterizedBeanPropertyRowMapper.newInstance(ComboBean.class);
		List<ComboBean> result = baseDao.getNamedParameterJdbcTemplate().query(sql,params, rowMapper);
		return result;
	}



	@Override
	public List<BsCategory> getL1AndL2Category() {
		String sql= CategorySql.getL1AndL2Category();
		RowMapper<BsCategory> rowMapper = ParameterizedBeanPropertyRowMapper.newInstance(BsCategory.class);
		List<BsCategory> result = baseDao.getNamedParameterJdbcTemplate().query(sql,new MapSqlParameterSource(), rowMapper);
		return result;
	}

	@Override
	public List<ComboBean> getL2Category() {
		String sql= CategorySql.getL2Category();
		RowMapper<ComboBean> rowMapper = ParameterizedBeanPropertyRowMapper.newInstance(ComboBean.class);
		List<ComboBean> result = baseDao.getNamedParameterJdbcTemplate().query(sql,new MapSqlParameterSource(), rowMapper);
		return result;
	}

	@Override
	public void deleteCategories(List<Long> ids) {
		String sql= CategorySql.deleteCategories();
		baseDao.getNamedParameterJdbcTemplate().update(sql,new MapSqlParameterSource().addValue("ids",ids));

	}








}